
const ua = window.navigator.userAgent;

const detectors = [

  /**
   * ------------------------------------------------------------------------
   * system
   * ------------------------------------------------------------------------
   */
  { name: 'isIOS', regex: /iPad|iPhone|iPod/i },
  { name: 'isAndroid', regex: /Android/i },
  { name: 'isWindowsPhone', regex: /WPDesktop|IEMobile|XBLWP\d+/i },
  { name: 'isBlackBerry', regex: /BlackBerry/i },


  /**
   * ------------------------------------------------------------------------
   * company
   * ------------------------------------------------------------------------
   */
  { name: 'isTencentApp', regex: /QQ|MicroMessenger/i },
  { name: 'isAliApp', regex: /AliApp/i },


  /**
   * ------------------------------------------------------------------------
   * application
   * ------------------------------------------------------------------------
   */
  { name: 'isWechat', regex: /MicroMessenger/i },
  { name: 'isWeibo', regex: /WeiBo/i },
  { name: 'isQQ', regex: /QQ/i },
  { name: 'isGUOGUO', regex: /AliApp\(CN/i },

  /**
   * ------------------------------------------------------------------------
   * device
   * ------------------------------------------------------------------------
   */
  { name: 'isIPhone', regex: /iPhone/i },
  { name: 'isIPad', regex: /iPad/i },
];

const browser = {};

detectors.forEach(detector => Object.defineProperty(browser, detector.name, {
  enumerable: true,
  value: detector.regex.test(ua)
}));

export default browser;
